using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Banshee.Base.Winforms.Widgets
{
    public class CoverArtView:PictureBox
    {
        

        public CoverArtView()
        {
            Dock = DockStyle.Bottom;
            SizeMode = PictureBoxSizeMode.StretchImage;
            EnabledChanged += new EventHandler(CoverArtView_EnabledChanged);
            BorderStyle = BorderStyle.None;
        }

        void CoverArtView_EnabledChanged(object sender, EventArgs e)
        {
            Visible = Enabled;
        }
        private Image pixbuf;
        public string FileName
        {
            set
            {
                try
                {
                    if (value == null)
                    {
                        pixbuf = null;
                        Visible = false;
                        return;
                    }

                    if (!System.IO.File.Exists(value))
                    {
                        throw new ApplicationException("Invalid file name");
                    }

                    pixbuf = Image.FromFile(value);
                    if (pixbuf == null)
                    {
                        throw new ApplicationException("Could not create pixbuf");
                    }
                    else
                    {
                        Image = pixbuf;
                        Visible = true;
                    }

                }
                catch (Exception)
                {
                    pixbuf = null;
                    Visible = false;
                }
            }
        }

    }
}
